package cc.rengu.redp.flowable.delegate;

import cc.rengu.redp.common.exception.RedpException;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class TestDelegate extends BaseDelegate {

    @Override
    public JSONObject doExecute(JSONObject jsonObject) throws Exception {
        Random random = new Random();
        if (random.nextBoolean()) {
            System.out.println("TestDelegate, return success.");
        } else {
            System.out.println("TestDelegate, return failed.");
            throw new RedpException("测试，错误返回");
        }

        return jsonObject;
    }

    @Override
    public String delegateSimpleDescription() {
        return "测试节点";
    }
}
